using CGF;
using LitJson;
using UnityEngine;

public struct Event_PluginMsg
{
    public string msg;
}

public class VideoPluginMsgListener : MonoBehaviour
{
    public static VideoPluginMsgListener instance;

    public static void Init()
    {
        if (!instance)
        {
            GameObject go = new GameObject(nameof(VideoPluginMsgListener));
            DontDestroyOnLoad(go);
            instance = go.AddComponent<VideoPluginMsgListener>();
        }
    }

    //Android 通过 UnityPlayer.UnitySendMessage 调用
    public void OnMsg(string msg)
    {
        Debug.Log($"投屏插件发来消息：{msg}");
        EventManager.Emit(new Event_PluginMsg() { msg = msg });
    }

    private void OnDestroy()
    {
        instance = null;
    }
}
